import { defineStore } from 'pinia'
import mockRequest from '@/utils/mockRequest'

export type CenterInfoData = {
  myPropertyList: MyPropertyData[],
  cardsList: CardData[],
  userInformation: {
    nickName: string,
    lv: string
  }
}
interface MyPropertyData {
  id: number,
  count: number,
  content: string
}
interface CardData {
  id: number,
  iconStyle: string,
  content: string
}
type CenterStoreStateData = {
  centerInfo: CenterInfoData
}
const useCenterStore = defineStore('center',{
  state():CenterStoreStateData{
    return {
      centerInfo: {
        "myPropertyList": [
          {
            "id": 1,
            "count": 123,
            "content": "余额"
          },
          {
            "id": 2,
            "count": 998,
            "content": "红包"
          },
          {
            "id": 3,
            "count": 3,
            "content": "优惠券"
          },
          {
            "id": 4,
            "count": 2201,
            "content": "积分"
          },
          {
            "id": 5,
            "count": 123,
            "content": "礼品卡"
          }
        ],
        "cardsList": [
          {
            "id": 14,
            "iconStyle": "description",
            "content": "我的订单"
          },
          {
            "id": 1,
            "iconStyle": "user-circle-o",
            "content": "账号管理"
          },
          {
            "id": 2,
            "iconStyle": "phone-o",
            "content": "我的手机号"
          },
          {
            "id": 3,
            "iconStyle": "calendar-o",
            "content": "周六一起拼"
          },
          {
            "id": 4,
            "iconStyle": "after-sale",
            "content": "售后服务"
          },
          {
            "id": 5,
            "iconStyle": "send-gift-o",
            "content": "邀请返利"
          },
          {
            "id": 6,
            "iconStyle": "fire-o",
            "content": "优先购"
          },
          {
            "id": 7,
            "iconStyle": "gold-coin-o",
            "content": "积分中心"
          },
          {
            "id": 8,
            "iconStyle": "vip-card-o",
            "content": "会员俱乐部"
          },
          {
            "id": 9,
            "iconStyle": "free-postage",
            "content": "地址管理"
          },
          {
            "id": 10,
            "iconStyle": "shield-o",
            "content": "支付安全"
          },
          {
            "id": 11,
            "iconStyle": "user-o",
            "content": "帮助与客服"
          },
          {
            "id": 12,
            "iconStyle": "records",
            "content": "意见反馈"
          },
          {
            "id": 13,
            "iconStyle": "gift-card-o",
            "content": "我的竞拍"
          }
        ],
        "userInformation": {
          "nickName": "用户2333",
          "lv": "普通用户"
        }
      }
    }
  },
  actions: {
    async getCenterInfo() {
      try {
        const res = await mockRequest('/getCenterInfo')
        if (res.data.code === 200) {
          this.centerInfo = res.data.data
          return 'ok'
        }
      } catch (error) {
        return Promise.reject('fail')
      }
    }
  }
})

export default useCenterStore